package com.addcn.android.design591.utils;

import android.content.Context;
import android.content.pm.PackageInfo;

/**
 * Created by xuge on 2016/12/30.
 * 工具类
 */

public class ToolUtils {


    /**
     * 获取版本号
     */
    public static int getVersionCode(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 获取版本名
     */
    public static String getVersionName(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionName;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String getImageUrl(String url) {
        if (url == null)
            return "";
        if (url.startsWith("//upload")) {
            url = "https:" + url;
        }
        return url;
    }
}
